package io.sage.ch01.v5;

/**
 * 电影
 */
public class Movie {
    // 儿童片
    public static final int CHILDRENS = 2;
    // 普通片
    public static final int REGULAR = 0;
    // 新片
    public static final int NEW_RELEASE = 1;

    // 标题
    private String _title;
    // 价格
    //private int _priceCode;
    private Price _price;

    public Movie(String title, int priceCode) {
        this._title = title;
        setPriceCode(priceCode);
    }

    public String getTitle() {
        return _title;
    }

    public int getPriceCode() {
        return _price.getPriceCode();
    }

    public void setPriceCode(int arg) {
        switch (arg) {
            case REGULAR:
                _price = new RegularPrice();
                break;
            case CHILDRENS:
                _price = new ChildrensPrice();
                break;
            case NEW_RELEASE:
                _price = new NewReleasePrice();
                break;
            default:
                throw new IllegalArgumentException("Incorrect Price Code");
        }

    }

    /**
     * 实施Move Method重构，移至Price类。
     *
     * @param daysRented
     * @return
     */
    public double getCharge(int daysRented) {
        return _price.getCharge(daysRented);
    }

    /**
     * 类似getCharge的处理方法，将其从Rental类移至Movie类
     *
     * @param daysRented
     * @return
     */
    public int getFrequentRenterPoints(int daysRented) {
        return _price.getFrequentRenterPoints(daysRented);
    }
}
